// 0 引入 用来发送请求的方法 一定要把路径补全
import { request } from "../../request/index.js";
Page({
  data: {
    //轮播图数组
    swiperList: [],
    //导航数组
    catesList: [],
    //楼层数据
    floorList:[]
  },
  //页面开始加载就会触发
  onLoad: function (options) {
    // 1.发送异步请求获取轮播图数据 优化的手段可以通过es6的 promise来解决
    // wx.request({
    //   url: 'https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata',
    //   success: (result)=>{  
    //     this.setData({
    //       swiperList: result.data.message
    //     })  
    //   }
    // });

    this.getSwiperList();
    this.getCateList();
    this.getFloorList();


  },
  //获取分类导航数据
  getSwiperList(){
    wx.request({
      url: 'https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata',
      success: (result)=>{
        let arr1 = result.data.message;
        arr1.forEach((v)=>{
          v.navigator_url=v.navigator_url.replace('main','index')
        })
        this.setData({
          swiperList:result.data.message
        })
      }
    });
  },  

 
  //获取分类导航数据
  getCateList(){
    request({ url: "/home/catitems" })
      .then(result => {
        this.setData({
          catesList: result
        })
        
      })
  },
  //获取楼层数据
  getFloorList(){
    wx.request({
      url: 'https://api-hmugo-web.itheima.net/api/public/v1/home/floordata',
      success: (result)=>{
        let arr1 = result.data.message;
        arr1.forEach((v,i)=>{
          v.product_list.forEach((v,i)=>{
            v.navigator_url=v.navigator_url.replace('?','/index?')
          })
        })
        this.setData({
          floorList:result.data.message
        })
      }
    });
  },
})